#include <bits/stdc++.h>
// 2025/01/24
// tag: 
// Author: Zhang Muen
using namespace std;

int n, m, bx, by, pos[1501][1501][2], dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0};
char maze[1501][1501];
bool vis[1501][1501];

bool dfs(int x, int y, int x1, int y1){
    if (vis[x][y] && (pos[x][y][0] != x1 || pos[x][y][1] != y1))
        return true;
    vis[x][y] = true, pos[x][y][0] = x1, pos[x][y][1] = y1;
    for (int i = 0; i < 4; i++){
        int nx = (x + dx[i] + n) % n, ny = (y + dy[i] + m) % m;
        if (maze[nx][ny] != '#')
            if (pos[nx][ny][0] != x1 + dx[i] || pos[nx][ny][1] != y1 + dy[i] || !vis[nx][ny])
                if (dfs(nx, ny, x1 + dx[i], y1 + dy[i]))
                    return true;
    }
    return false;
}

signed main()
{
    while (cin >> n >> m)
    {
        memset(vis, 0, sizeof(vis));
        memset(pos, 0, sizeof(pos));
        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++){
                cin >> maze[i][j], pos[i][j][0] = i, pos[i][j][1] = j;
                if (maze[i][j] == 'S')
                    bx = i, by = j;
            }
        cout << (dfs(bx, by, bx, by) ? "Yes" : "No")<< endl;
    }

    return 0;
}